/*
 * SafeNativeMethods.cs
 *
 * Contains Safe P/Invoke Methods.
 *
 * Copyright (c) 2005, dnAnalytics. All rights reserved.
 */
using System.Runtime.InteropServices;
using System.Security;
using dnAnalytics.Math;

namespace dnAnalytics.LinearAlgebra.Native.Acml
{
    [SuppressUnmanagedCodeSecurity]
    internal static class SafeNativeMethods
    {
        private const string dllName = "libacml_dll.dll";

        #region PInvoke calls

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double ddot(int n,  double[] x, int incX,  double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern Complex zdotu(int n,  Complex[] x, int incX,  Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern Complex zdotc(int n,  Complex[] x, int incX,  Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double dnrm2(int n,  double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double dasum(int n,  double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double dznrm2(int n,  Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double dzasum(int n,  Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int idamax(int n,  double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int izamax(int n,  Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dswap(int n, [In, Out] double[] x, int incX, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dcopy(int n,  double[] x, int incX, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void daxpy(int n, double alpha,  double[] x, int incX, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void drotg(ref double a, ref double b, out double c, out double s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zswap(int n, [In, Out] Complex[] x, int incX, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zcopy(int n,  Complex[] x, int incX, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zaxpy(int n, ref Complex alpha,  Complex[] x, int incX, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zrotg(ref Complex a, ref Complex b, out Complex c, out Complex s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void drotmg(double d1, double d2, double x1, double y1, [In, Out] double[] p);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void drot(int n, [In, Out] double[] x, int incX, [In, Out] double[] y, int incY, double c, double s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void drotm(int n, [In, Out] double[] x, int incX, [In, Out] double[] y, int incY, [In, Out] double[] p);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zdrot(int n, [In, Out] Complex[] x, int incX, [In, Out] Complex[] y, int incY, double c, double s);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dscal(int n, double alpha, [In, Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zscal(int n, ref Complex alpha, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zdscal(int n, double alpha, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgemv(char transA, int m, int n, double alpha,  double[] a, int lda,  double[] x, int incX, double beta, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgbmv(char transA, int m, int n, int kl, int ku, double alpha,  double[] a, int lda,  double[] x, int incX, double beta, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtrmv(char uplo, char transA, char diag, int n,  double[] a, int lda, [In, Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtbmv(char uplo, char transA, char diag, int n, int k,  double[] a, int lda, [In, Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtpmv(char uplo, char transA, char diag, int n,  double[] ap, [In, Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtrsv(char uplo, char transA, char diag, int n,  double[] a, int lda, [In, Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtbsv(char uplo, char transA, char diag, int n, int k,  double[] a, int lda, [In, Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtpsv(char uplo, char transA, char diag, int n,  double[] ap, [In, Out] double[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgemv(char transA, int m, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgbmv(char transA, int m, int n, int kl, int ku, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztrmv(char uplo, char transA, char diag, int n,  Complex[] a, int lda, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztbmv(char uplo, char transA, char diag, int n, int k,  Complex[] a, int lda, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztpmv(char uplo, char transA, char diag, int n,  Complex[] ap, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztrsv(char uplo, char transA, char diag, int n,  Complex[] a, int lda, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztbsv(char uplo, char transA, char diag, int n, int k,  Complex[] a, int lda, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztpsv(char uplo, char transA, char diag, int n,  Complex[] ap, [In, Out] Complex[] x, int incX);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dsymv(char uplo, int n, double alpha,  double[] a, int lda, double[] x, int incX, double beta, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dsbmv(char uplo, int n, int k, double alpha,  double[] a, int lda,  double[] x, int incX, double beta, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dspmv(char uplo, int n, double alpha,  double[] ap,  double[] x, int incX, double beta, [In, Out] double[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dger(int m, int n, double alpha,  double[] x, int incX,  double[] y, int incY, [In, Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dsyr(char uplo, int n, double alpha,  double[] x, int incX, [In, Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dspr(char uplo, int n, double alpha,  double[] x, int incX, [In, Out] double[] ap);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dsyr2(char uplo, int n, double alpha,  double[] x, int incX,  double[] y, int incY, [In, Out] double[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dspr2(char uplo, int n, double alpha,  double[] x, int incX,  double[] y, int incY, [In, Out] double[] a);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zhemv(char uplo, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zhbmv(char uplo, int n, int k, ref Complex alpha,  Complex[] a, int lda,  Complex[] x, int incX, ref Complex beta, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zhpmv(char uplo, int n, ref Complex alpha,  Complex[] ap,  Complex[] x, int incX, ref Complex beta, [In, Out] Complex[] y, int incY);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgeru(int m, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [In, Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgerc(int m, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [In, Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zher(char uplo, int n, double alpha,  Complex[] x, int incX, [In, Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zhpr(char uplo, int n, double alpha,  Complex[] x, int incX, [In, Out] Complex[] a);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zher2(char uplo, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [In, Out] Complex[] a, int lda);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zhpr2(char uplo, int n, ref Complex alpha,  Complex[] x, int incX,  Complex[] y, int incY, [In, Out] Complex[] ap);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgemm(char transA, char transB, int m, int n, int k, double alpha,  double[] a, int lda,  double[] b, int ldb, double beta, [In, Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dsymm(char side, char uplo, int m, int n, double alpha,  double[] a, int lda,  double[] b, int ldb, double beta, [In, Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dsyrk(char uplo, char trans, int n, int k, double alpha,  double[] a, int lda, double beta, [In, Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dsyr2k(char uplo, char trans, int n, int k, double alpha,  double[] a, int lda,  double[] b, int ldb, double beta, [In, Out] double[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtrmm(char side, char uplo, char transA, char diag, int m, int n, double alpha,  double[] a, int lda, [In, Out] double[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dtrsm(char side, char uplo, char transA, char diag, int m, int n, double alpha,  double[] a, int lda, [In, Out] double[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgemm(char transA, char transB, int m, int n, int k, ref Complex alpha,  Complex[] a, int lda, Complex[] b, int ldb, ref Complex beta, [In, Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zsymm(char side, char uplo, int m, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, ref Complex beta, [In, Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zsyrk(char uplo, char trans, int n, int k, ref Complex alpha,  Complex[] a, int lda, ref Complex beta, [In, Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zsyr2k(char uplo, char trans, int n, int k, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, ref Complex beta, [In, Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztrmm(char side, char uplo, char transA, char diag, int m, int n, ref Complex alpha,  Complex[] a, int lda, [In, Out] Complex[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ztrsm(char side, char uplo, char transA, char diag, int m, int n, ref Complex alpha,  Complex[] a, int lda, [In, Out] Complex[] b, int ldb);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zhemm(char side, char uplo, int m, int n, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, ref Complex beta, [In, Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zherk(char uplo, char trans, int n, int k, double alpha,  Complex[] a, int lda, double beta, [In, Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zher2k(char uplo, char trans, int n, int k, ref Complex alpha,  Complex[] a, int lda,  Complex[] b, int ldb, double beta, [In, Out] Complex[] c, int ldc);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGEQP3(ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] int[] jpvt, [In, Out] double[] tau, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGESVD(ref char jobu, int ulen, ref char jobvt, int vlen, ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] double[] s, [In, Out] double[] u, ref int ldu, [In, Out] double[] vt, ref int ldvt, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGETRF(ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] int[] ipiv, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGETRI(ref int n, [In, Out] double[] a, ref int lda,  int[] ipiv, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGETRS(ref char trans, int len, ref int n, ref int nrhs,  double[] a, ref int lda,  int[] ipiv, [In, Out] double[] b, ref int ldb, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DORGQR(ref int m, ref int n, ref int k, [In, Out] double[] a, ref int lda,  double[] tau, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DORMQR(ref char side, int slen, ref char trans, int tlen, ref int m, ref int n, ref int k,  double[] a, ref int lda,  double[] tau, [In, Out] double[] c, ref int ldc, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DPOTRF(ref char uplo, int len, ref int n, [In, Out] double[] a, ref int lda, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DPOTRI(ref char uplo, int len, ref int n, [In, Out] double[] a, ref int lda, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DPOTRS(ref char uplo, int len, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGEQP3(ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] int[] jpvt, [In, Out] Complex[] tau, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGETRF(ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] int[] ipiv, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGETRI(ref int n, [In, Out] Complex[] a, ref int lda,  int[] ipiv, [In, Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGETRS(ref char trans, int len, ref int n, ref int nrhs,  Complex[] a, ref int lda,  int[] ipiv, [In, Out] Complex[] b, ref int ldb, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZPOTRF(ref char uplo, int len, ref int n, [In, Out] Complex[] a, ref int lda, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZPOTRI(ref char uplo, int len, ref int n, [In, Out] Complex[] a, ref int lda, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZPOTRS(ref char uplo, int len, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZUNGQR(ref int m, ref int n, ref int k, [In, Out] Complex[] a, ref int lda,  Complex[] tau, [In, Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZUNMQR(ref char side, int slen, ref char trans, int tlen, ref int m, ref int n, ref int k,  Complex[] a, ref int lda,  Complex[] tau, [In, Out] Complex[] c, ref int ldc, [In, Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGESVD(ref char jobu, int ulen, ref char jobvt, int vlen, ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] double[] s, [In, Out] Complex[] u, ref int ldu, [In, Out] Complex[] v, ref int ldvt, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGELS(ref char trans, int len, ref int m, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, [In, Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGELS(ref char trans, int len, ref int m, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGELSS(ref int m, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, [In, Out] double[] s, ref double rcond, ref int rank, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGELSS(ref int m, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, [In, Out] double[] s, ref double rcond, ref int rank, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGELSY(ref int m, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, [In, Out] int[] jpvt, ref double rcond, ref int rank, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGELSY(ref int m, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, [In, Out] int[] jpvt, ref double rcond, ref int rank, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double DLANGE(ref char norm, int len, ref int m, ref int n,  double[] a, ref int lda,  double[] work);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double ZLANGE(ref char norm, int len, ref int m, ref int n,  Complex[] a, ref int lda,  double[] work);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGECON(ref char norm, int len, ref int n,  double[] a, ref int lda, ref double anorm, ref double rcond,  double[] work,  int[] iwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGECON(ref char norm, int len, ref int n,  Complex[] a, ref int lda, ref double anorm, ref double rcond,  Complex[] work,  double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int ILAENV(ref int ispec, string name, string opts, ref int n1, ref int n2, ref int n3, ref int n4, int nlen, int olen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGEQRF(ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] double[] tau, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGEQRF(ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] tau, [In, Out] Complex[] work, ref int lwork, ref int info);

        // For IFORT versions		
        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGESVD(ref char jobu, ref char jobvt, ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] double[] s, [In, Out] double[] u, ref int ldu, [In, Out] double[] vt, ref int ldvt, [In, Out] double[] work, ref int lwork, ref int info, int ulen, int vlen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGETRS(ref char trans, ref int n, ref int nrhs, double[] a, ref int lda, int[] ipiv, [In, Out] double[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DORMQR(ref char side, ref char trans, ref int m, ref int n, ref int k, double[] a, ref int lda, double[] tau, [In, Out] double[] c, ref int ldc, [In, Out] double[] work, ref int lwork, ref int info, int slen, int tlen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DPOTRF(ref char uplo, ref int n, [In, Out] double[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DPOTRI(ref char uplo, ref int n, [In, Out] double[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DPOTRS(ref char uplo, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGETRS(ref char trans, ref int n, ref int nrhs, Complex[] a, ref int lda, int[] ipiv, [In, Out] Complex[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZPOTRF(ref char uplo, ref int n, [In, Out] Complex[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZPOTRI(ref char uplo, ref int n, [In, Out] Complex[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZPOTRS(ref char uplo, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZUNMQR(ref char side, ref char trans, ref int m, ref int n, ref int k, Complex[] a, ref int lda, Complex[] tau, [In, Out] Complex[] c, ref int ldc, [In, Out] Complex[] work, ref int lwork, ref int info, int slen, int tlen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGESVD(ref char jobu, ref char jobvt, ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] double[] s, [In, Out] Complex[] u, ref int ldu, [In, Out] Complex[] v, ref int ldvt, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info, int ulen, int vlen);

         [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGELS(ref char trans, ref int m, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, [In, Out] Complex[] work, ref int lwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGELS(ref char trans, ref int m, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, [In, Out] double[] work, ref int lwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double DLANGE(ref char norm, ref int m, ref int n, double[] a, ref int lda, double[] work, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double ZLANGE(ref char norm, ref int m, ref int n, Complex[] a, ref int lda, double[] work, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void DGECON(ref char norm, ref int n, double[] a, ref int lda, ref double anorm, ref double rcond, double[] work, int[] iwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void ZGECON(ref char norm, ref int n, Complex[] a, ref int lda, ref double anorm, ref double rcond, Complex[] work, double[] rwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int ILAENV(ref int ispec, string name, int nlen, string opts, int olen, ref int n1, ref int n2, ref int n3, ref int n4);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgeqp3_(ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] int[] jpvt, [In, Out] double[] tau, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgesvd_(ref char jobu, ref char jobvt, ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] double[] s, [In, Out] double[] u, ref int ldu, [In, Out] double[] vt, ref int ldvt, [In, Out] double[] work, ref int lwork, ref int info, int ulen, int tlen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgetrf_(ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] int[] ipiv, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgetri_(ref int n, [In, Out] double[] a, ref int lda,  int[] ipiv, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgetrs_(ref char trans, ref int n, ref int nrhs,  double[] a, ref int lda,  int[] ipiv, [In, Out] double[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dorgqr_(ref int m, ref int n, ref int k, [In, Out] double[] a, ref int lda,  double[] tau, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dormqr_(ref char side, ref char trans, ref int m, ref int n, ref int k,  double[] a, ref int lda,  double[] tau, [In, Out] double[] c, ref int ldc, [In, Out] double[] work, ref int lwork, ref int info, int slen, int tlen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dpotrf_(ref char uplo, ref int n, [In, Out] double[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dpotri_(ref char uplo, ref int n, [In, Out] double[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dpotrs_(ref char uplo, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgeqp3_(ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] int[] jpvt, [In, Out] Complex[] tau, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgetrf_(ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] int[] ipiv, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgetri_(ref int n, [In, Out] Complex[] a, ref int lda,  int[] ipiv, [In, Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgetrs_(ref char trans, ref int n, ref int nrhs,  Complex[] a, ref int lda,  int[] ipiv, [In, Out] Complex[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zpotrf_(ref char uplo, ref int n, [In, Out] Complex[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zpotri_(ref char uplo, ref int n, [In, Out] Complex[] a, ref int lda, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zpotrs_(ref char uplo, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zungqr_(ref int m, ref int n, ref int k, [In, Out] Complex[] a, ref int lda,  Complex[] tau, [In, Out] Complex[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zunmqr_(ref char side, ref char trans, ref int m, ref int n, ref int k,  Complex[] a, ref int lda,  Complex[] tau, [In, Out] Complex[] c, ref int ldc, [In, Out] Complex[] work, ref int lwork, ref int info, int slen, int tlen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgesvd_(ref char jobu, ref char jobvt, ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] double[] s, [In, Out] Complex[] u, ref int ldu, [In, Out] Complex[] v, ref int ldvt, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info, int ulen, int tlen);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgels_(ref char trans, ref int m, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, [In, Out] Complex[] work, ref int lwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgels_(ref char trans, ref int m, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, [In, Out] double[] work, ref int lwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgelss_(ref int m, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, [In, Out] double[] s, ref double rcond, ref int rank, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgelss_(ref int m, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, [In, Out] double[] s, ref double rcond, ref int rank, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgelsy_(ref int m, ref int n, ref int nrhs, [In, Out] double[] a, ref int lda, [In, Out] double[] b, ref int ldb, [In, Out] int[] jpvt, ref double rcond, ref int rank, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgelsy_(ref int m, ref int n, ref int nrhs, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] b, ref int ldb, [In, Out] int[] jpvt, ref double rcond, ref int rank, [In, Out] Complex[] work, ref int lwork, [In, Out] double[] rwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double dlange_(ref char norm, ref int m, ref int n,  double[] a, ref int lda,  double[] work, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern double zlange_(ref char norm, ref int m, ref int n,  Complex[] a, ref int lda,  double[] work, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgecon_(ref char norm, ref int n,  double[] a, ref int lda, ref double anorm, ref double rcond,  double[] work,  int[] iwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgecon_(ref char norm, ref int n,  Complex[] a, ref int lda, ref double anorm, ref double rcond,  Complex[] work,  double[] rwork, ref int info, int len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int ilaenv_(ref int ispec, string name, string opts, ref int n1, ref int n2, ref int n3, ref int n4, int name_len, int opts_len);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void dgeqrf_(ref int m, ref int n, [In, Out] double[] a, ref int lda, [In, Out] double[] tau, [In, Out] double[] work, ref int lwork, ref int info);

        [DllImport(dllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void zgeqrf_(ref int m, ref int n, [In, Out] Complex[] a, ref int lda, [In, Out] Complex[] tau, [In, Out] Complex[] work, ref int lwork, ref int info);

        #endregion PInvoke calls
    }
}